package com.huluobo.a2204kotlinjetpackdemo.livedata;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;
import android.widget.TextView;

import com.huluobo.a2204kotlinjetpackdemo.R;

import org.w3c.dom.Text;

public class StudentActivity extends AppCompatActivity {

    private StudentViewModel studentViewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_student);

        TextView studentTv = findViewById(R.id.student_tv);
        studentViewModel = new ViewModelProvider(this).get(StudentViewModel.class);

        Student student = new Student("LC", "0", 90);
        studentViewModel.setStudent(student);

        studentViewModel.get_student().observe(this, score -> {
            studentTv.setText("分数:" + score);
        });

    }
}